package com.htrq.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.htrq.entity.TResource;
import com.htrq.entity.User;
import com.htrq.service.HRoleReService;
import com.htrq.service.LoginService;

@Controller
@RequestMapping("jsp/sys")
public class HRoleResController {
	@Resource
	private HRoleReService rlsService;
	
	@Resource
	private LoginService loginService;
	
	@RequestMapping("saverolres")
	@ResponseBody
	public String saverolres(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String rid = request.getParameter("rid");
		String resids = request.getParameter("resids");
		boolean flag = rlsService.savers(rid, resids);
		response.setContentType("text/html;charset=utf8");
		PrintWriter out = response.getWriter();
		if (flag) {
			out.print("保存成功");
		}else{
			out.print("保存失败");
		}
		return null;
	}
	
	@RequestMapping("getTResByrid")
	@ResponseBody
	public String getTResByrid(User user,HttpServletResponse response) throws IOException{
		List<TResource> rights = loginService.getRightByUser(user);
		String json=JSON.toJSONString(rights);
		response.setContentType("text/html;charset=utf8");
		PrintWriter out = response.getWriter();
		out.print(json);
		return null;
	}
}
